package com.zzr.demo.alipay.controller;

import com.zzr.demo.alipay.service.ThirdPayService;
import com.zzr.demo.alipay.vo.PayRequest;
import com.zzr.demo.alipay.vo.ResultStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author: xiaomi
 * @date: 2021/8/31
 * @description:
 */
@Slf4j
@RestController
@RequestMapping("thirdPay")
public class ThirdPayController {

    @Resource
    private ThirdPayService thirdPayService;

    /**
     * aliPayCertUnifiedOrder
     * 支付宝下订单接口
     * 参数可根据自己的业务需求传相应参数
     *
     * @param request
     * @return
     */
    @GetMapping(value = "aliPayUnifiedOrder")
    public ResultStatus aliPayUnifiedOrder(PayRequest request) {

        return thirdPayService.aliPayUnifiedOrder(request);
    }

    /**
     * 支付宝回调接口
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "aliPayNotify")
    @ResponseBody
    public String aliPayNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
        //获取支付宝POST过来反馈信息
        Map requestParams = request.getParameterMap();
        return thirdPayService.aliPayNotify(requestParams);
    }

    /**
     * 支付宝下订单接口(公钥证书方式)
     * 参数可根据自己的业务需求传相应参数
     *
     * @param request
     * @return
     */
    @GetMapping(value = "aliPayCertUnifiedOrder")
    public ResultStatus aliPayCertUnifiedOrder(PayRequest request) {

        return thirdPayService.aliPayCertUnifiedOrder(request);
    }

    /**
     * 支付宝回调接口(公钥证书方式)
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @PostMapping(value = "aliPayCertNotify")
    @ResponseBody
    public String aliPayCertNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
        //获取支付宝POST过来反馈信息
        Map requestParams = request.getParameterMap();
        return thirdPayService.aliPayCertNotify(requestParams);
    }
}
